Skip to content

feat: spm support for rn 0.89 - #449

Closed
VladyslavMartynov10 wants to merge 1 commit into
duguyihou:mainfrom
VladyslavMartynov10:feat/spm-support
Closed

VladyslavMartynov10 wants to merge 1 commit into
duguyihou:mainfrom
VladyslavMartynov10:feat/spm-support

Conversation

@VladyslavMartynov10

Copy link
Copy Markdown

SPM support

React Native 0.87 added Swift Package Manager as an alternative to CocoaPods on iOS (npx react-native spm), and 0.88 stabilised it. The plan for 0.89 is to make SwiftPM the default for new apps, with CocoaPods as the opt-out (see react-native-community/cli#2881). In SwiftPM mode the autolinker needs every native library to ship a Package.swift; a library without one fails package resolution for the whole app unless the user scaffolds and patches a manifest locally.

react-native-turbo-image currently ships only a podspec, so it cannot be used in a SwiftPM app today.

What this PR does

Adds a Package.swift and the few source changes SwiftPM needs. CocoaPods is unchanged; the podspec stays the source of truth for that path.

Package.swift (new)

  • Two targets, because SwiftPM cannot mix Swift and Objective-C in one target:
    • TurboImage (Swift): the view, view manager, extensions and utilities.
    • TurboImageObjC: TurboImageViewManager.m only, i.e. the RCT_EXTERN_MODULE declarations. It references the Swift class by name, so it does not import the Swift target.
  • Both targets are exported in one product, TurboImage.
  • Dependencies: React Native's prebuilt header packages (resolved through the autolinker's build/generated/autolinking/libs/TurboImage symlink, so the manifest only resolves inside an app, same as react-native-safe-area-context and react-native-pager-view), plus Nuke/NukeUI, Gifu and APNGKit as SwiftPM source packages instead of the vendored xcframeworks and pods.
    • Nuke 12.8.0..<13.0.0, the same major as the vendored 12.8.0 frameworks.
    • Gifu 3.3.1..<4.0.0. Gifu 4.0.x ships a Package@swift-6.0.swift manifest with an iOS 16 floor, which current Xcode toolchains select, and React Native's autolinking package sits at the app's deployment target with a 15.1 floor, so Gifu 4 cannot be resolved from a default RN app. 3.x is also what CocoaPods resolves today.
    • APNGKit from: 2.3.0.

ios/TurboImageViewManager.swift

  • import React. SwiftPM has no bridging headers; under CocoaPods TurboImage-Bridging-Header.h provided RCTViewManager.

  • The class is now public, view() returns UIView!, and requiresMainQueueSetup() is public. With the RCT_EXTERN_MODULE category in a separate target, an optimized build hides an internal Swift class's Objective-C symbol and the Release link fails with Undefined symbols: _OBJC_CLASS_$_TurboImageViewManager.
    ios/Extensions/UIImage+BorderRadius.swift, ios/Extensions/UIImage+Thumbhash.swift

  • import UIKit. CocoaPods provided it through the umbrella header.

package.json

  • Package.swift added to files, otherwise it is not published.
  • swiftpmConfig.name: "TurboImage", the product name the autolinker links.

How it was tested

Fresh app from @react-native-community/cli@20.2.0 init --version 0.88.1, converted with npx react-native spm add --deintegrate, this package installed from npm pack output. Xcode 26.6, iPhone 17 Pro simulator (iOS 26.5).

@duguyihou

Copy link
Copy Markdown
Owner

Thanks for putting this together. For 2.0 we've decided that apps install the iOS part through CocoaPods only. The Swift package in the repository is used only to run the library's own tests, and supporting it for apps would mean building and testing two install paths. The reasoning is in ADR 0015 (https://github.com/duguyihou/react-native-turbo-image/blob/main/docs/adr/0015-cocoapods-only-for-apps.md). 2.0 also restructures the iOS sources, so the files this PR changes no longer exist.

If that changes, for example once React Native itself moves apps to Swift Package Manager, we'll revisit it. Closing this one, but thank you.

@duguyihou duguyihou closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants